home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1999 March
/
EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso
/
earcd
/
devel
/
vbcc-68k-src
/
machines
/
amiga68k
/
libsrc
/
stdio
/
freopen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-01
|
1KB
|
45 lines
#include <stddef.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <proto/dos.h>
extern FILE *_firstfile,*_lastfile;
extern char *_stdin,*_stdout,*_stderr;
FILE *freopen(const char *name,const char *mode,FILE *f)
{
long amigamode=0;int append;
if(f->filehandle){
fflush(f);
if(f->filehandle!=_stdin&&f->filehandle!=_stdout&&f->filehandle!=_stderr)
Close((BPTR)f->filehandle); /* hier returncode auswerten */
if(f->prev) f->prev->next=f->next; else _firstfile=f->next;
if(f->next) f->next->prev=f->prev; else _lastfile=f->prev;
if(f->base&&!(f->flags&_NOTMYBUF)) free(f->base-1);
}
if(*mode=='w') amigamode=MODE_NEWFILE; else amigamode=MODE_OLDFILE;
if(*mode=='a') append=1; else append=0;
f->count=0;
f->base=0;
f->bufsize=0;
f->next=0;
if(*mode=='r') f->flags=_READABLE; else f->flags=_WRITEABLE;
if(*++mode=='b') mode++;
if(*mode=='+') {f->flags|=_READABLE|_WRITEABLE;amigamode=MODE_READWRITE;}
f->filehandle=(char *)Open((STRPTR)name,amigamode);
if(!f->filehandle){free(f);return(0);}
if(IsInteractive((BPTR)f->filehandle)) f->flags|=_LINEBUF;
if(_lastfile){
_lastfile->next=f;f->prev=_lastfile;_lastfile=f;
}else{
_firstfile=_lastfile=f;
}
if(append) fseek(f,0,SEEK_END);
return(f);
}